<template>
  <div class="left-chart-1">
    <div class="lc1-header">设备运行信息</div>
    <div class="lc1-details">设备运行总数
      <span>{{ amount }}</span>
    </div>
    <dv-capsule-chart
      class="lc1-chart"
      :config="config"
    />
    <dv-decoration-2 style="height:10px;" />
  </div>
</template>

<script>
export default {
  name: 'LeftChart1',
  props: {
    devicesData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {
      config: {}
    }
  },
  computed: {
    amount() {
      return this.config.data.map(val => val.value).reduce((sum, curr) => sum + curr, 0)
    }
  },
  watch: {
    devicesData: {
      handler(newVal, oldVal) {
        this.config = {
          data: newVal,
          colors: ['#00baff', '#3de7c9', '#fff', '#ffc530', '#469f4b'],
          unit: '个'
        }
      },
      deep: true,
      immediate: true
    }
  }
}
</script>

<style lang="scss">
.left-chart-1 {
  width: 100%;
  height: 50%;
  display: flex;
  flex-grow: 0;
  flex-direction: column;

  .lc1-header {
    text-align: center;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 10px;
  }

  .lc1-details {
    height: 50px;
    font-size: 16px;
    display: flex;
    align-items: center;
    text-indent: 20px;

    span {
      color: #096dd9;
      font-weight: bold;
      font-size: 35px;
      margin-left: 20px;
    }
  }

  .lc1-chart {
    flex: 1;
  }
}
</style>
